
package Objects;

import GameEngine.GameConstants.Effect;
import GameEngine.GameConstants.Graphic;
import GameEngine.GameConstants.Material;
import GameEngine.GameConstants.Modifier;
import GameEngine.GameConstants.Thing;
import GameEngine.Vector;

/**
 * This object will create wind objects every few iterations.
 *
 * Also implements the vacuum object type.
 * @author mhfowler
 */
public class Fan extends GameObject
{

    // instance variables
    private int fanPower;


    public Fan(Vector d, Vector cen, Vector s) {
        super(d, cen, s, Graphic.FAN);
        material = Material.WALL;
    }

    /**
     * "copy" constructor
     * @param vac
     */

    public Fan(Vacuum vac) {
        super(vac.getDir(), vac.getCenter(), vac.getSize(), Graphic.FAN);
        material = Material.WALL;
    }

    /* set the strenght of the fan */
    public void setFanPower(int strength) {
        fanPower = strength;
    }

    public int getFanPower() {
        return fanPower;
    }

     /** this method will be called on every object at the beginning of every iteration. In this method
     * particular objects may do specific things, such as arbitrarily update their own attributes based
     * on some correlation to their lifetime (how long they've existed...eg chompers updating their deltaPosition
     * up or down), or even causing an effect on other objects. But every object must iterate through the
     * list of persistent effects on them and receive them.
     */
    @Override
    public void nextIteration() {
        // first apply persistent
        super.applyPersistent();

        if (lifetime % 20 == 0) {

            /* create wind to be direction you face */
            Vector windSize = new Vector(2.2*size.getX(), size.getY());

            Vector windCen = direction.scaleNew(2.2*size.getX() - size.getX()/2);
            windCen.add(center);

            Wind toCreate = new Wind(direction, windCen, windSize, Graphic.WIND);
            toCreate.setWind(direction.scaleNew((double) fanPower));
            /* tell parent you created this object */
            lev.createObject(toCreate);
        }

        // then do physics
        super.doPhysics();
        // then undo persitent
        super.cancelPersistent();
    }


    @Override
    public void receiveEffect(Effect e, Vector m, int power) {
        switch (e) {
            case TRANSMUTE:
                Vacuum vac = new Vacuum(this);
                vac.setVacPower(fanPower);
                lev.createObject(vac);
                this.receiveEffect(Effect.DESTROY, null, 0);
                break;
            case SPEED:
                changed = true;
                fanPower += power;
                break;
            case SLOW:
                changed = true;
                fanPower -= power;
                break;
            case CURRENT:
                // do nothing
                break;
            case REVERSE:
                // do nothing
                break;
            case EXPLOSION:
                // do nothing
                break;
            default:
                super.receiveEffect(e, m, power);
                break;
        }
    }






}
